<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<%@include file="head.jsp"%>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/echarts.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.9.1.js"></script>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css" type="text/css" />
</head>
<body>
	<div class="dddiv"
		style="background-color: #F2F2F2; width: 1350px; height: 800px; margin-left: auto; margin-right: auto">
		<div class="dadiv" style="top: 20px;">
			<div class="divbody" style="width: 1000px; left: 0px;">
			<p
				style="background-color: #23262E; line-height: 40px; color: #F2F2F2;">销售分析</p>
				<div id="mains" style="width: 600px; height: 400px;"></div>
				<div id="mains2" style="width: 600px; height: 400px;"></div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	Array.prototype.notempty = function() {
	    var arr = [];
	    this.map(function(val, index) {
	        //过滤规则为，不为空串、不为null、不为undefined，也可自行修改
	        if (val !== "" && val != undefined) {
	            arr.push(val);
	        }
	    });
	    return arr;
	}	
function ToTime (time) {
    var dateObj = new Date(time)
    var month = dateObj.getMonth() + 1 // 获取月，必须要加1，因为月份是从0开始计算的
    var date = dateObj.getDate() // 获取日，记得区分getDay()方法是获取星期几的。
    return month + '-' + date
}
var myChart = echarts.init(document.getElementById('mains'));
var myChart2 = echarts.init(document.getElementById('mains2'));

$.ajax({	
	type:"get",
	url:"http://localhost:7788/hotel2.0/admin/findOrderData",
	data:{},
	dataType:"json", 	
	success:function(data){
		var x=[];
		var y=[];
		var i = 0;
		x.push(ToTime(data[i].ordertime));
		y.push(data[i].product.price);
		i=i+1;
		for(;i<data.length;i++){
			if (ToTime(data[i-1].ordertime)==ToTime(data[i].ordertime)) {
				y[i]=data[i].product.price+y[i-1];
				delete y[i-1];
			}else{
				x.push(ToTime(data[i].ordertime));
				y.push(data[i].product.price);
			}
		}
		
		var yy=y.notempty();
		
		myChart.setOption({
			 title: { 
	   			text: '近七天的交易额'
			 },
			tooltip: {},
			legend: {
			   data:['销售额']
			},
			xAxis: {
	   			data: x
			},
			yAxis: {},
			series: [{
	 		  name: '销售额',
	   		type: 'bar',
	   		data: yy
				}]
				});
	}
}) 

</script>
</body>
</html>